<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      div {
        width: 200px;
        height: 200px;
        background-color: aquamarine;
      }
      .action {
        background-color: skyblue;
        color: red;
        border: 3px dashed yellow;
        margin: 100px auto;
      }
    </style>
  </head>
  <body>
    <div class="nav">123</div>
    <script>
      const nav = document.querySelector('.nav')
      //增加一个类名修改样式
      // nav.classList.add('action')
      //移除类名
      // nav.classList.remove('action')
      //切换类名  toggle
      // 1.如果原来有这个类名就移除这个类名
      // nav.classList.add('action')
      // nav.classList.toggle('action')
      // 2.如果没有这个类名就增加这个类名
      nav.classList.toggle('action')
    </script>
  </body>
</html>
